import * as ospf from "./ospf conf 1221.json";

const data = ospf.default;
const posList = ["-300 -300", "0 -150", "300 -300", "250 500"];

export const NodeType = {
  ROUTER: 0,
  SWITCH: 1,
};

export const viewJson = () => {
  console.log("aaaa", data);
};

export const getNodes = (rawNode, rawSwitch) => {
  const nodes = rawNode.map((r, i) => {
    const node = {
      key: r.name,
      type: "ROUTER",
      text: r.name,
      portLists: r.port,
      command: r.command,
      loc: posList[i],
      // pic: routerPic
    };
    return node;
  });
  return nodes;
};
export const getNodesA = () => {
  const nodes = data.router.map((r, i) => {
    const node = {
      key: r.name,
      type: "ROUTER",
      text: r.name,
      portLists: r.port,
      command: r.command,
      loc: posList[i],
      // pic: routerPic
    };
    return node;
  });

  nodes.push({
    key: data.switch.name,
    type: "SWITCH",
    text: data.switch.name,
    // pic: routerPic
  });
  return nodes;
};

export const getLinks = (rawLink) => {
  const links = rawLink
    .filter((l) => l.logicalConnected)
    .map((l) => {
      const link = {
        from: l.from[0],
        to: l.to[0],
        fromPort: l.from[1],
        toPort: l.to[1],
      };
      return link;
    });
  return links;
};

export const getLinksA = () => {
  const links = data.line
    .filter((l) => l.logicalConnected)
    .map((l) => {
      const link = {
        from: l.from[0],
        to: l.to[0],
        fromPort: l.from[1],
        toPort: l.to[1],
      };
      return link;
    });
  return links;
};

export const getModal = () => {
  const modal = {
    nodeDataArray: getNodes(data.router),
    linkDataArray: getLinks(data.line),
  };

  return modal;
};
